Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: socket #445

Merged
merged 40 commits into from
Sep 14, 2023
Merged

feat: socket #445

merged 40 commits into from
Sep 14, 2023

Conversation

thantos
Copy link
Contributor

@thantos thantos commented Sep 12, 2023

Tasks:

  • Core
    • Socket Call
    • Socket Resource + Spec
    • Socket Physical Name Property
    • Socket Handler
  • Runtime
    • Client
    • Workers
      • Socket Call Executor
      • Socket Physical Name Retriever
      • Socket Handler Worker
    • Workflow
      • Socket Workflow Events
      • Socket Call Workflow Executor
      • Socket Call Workflow Eventual Factory
      • Wire Up Factory, Executor, and SocketName property
    • Transaction Worker
      • Support new Properties
      • Support Call is applicable
    • Replay
      • Wire up Properties
  • Infer
    • transform and assign new resources
    • add sourceLocation to handlers
  • Build
    • Bundle new worker
  • CLI
    • update display/events.ts with new events/fields
    • Output important service information
  • Environment
    • AWS
      • AWS Socket Client
      • Dep Injection
      • AWS Socket Worker
      • Update other workers
    • Local
      • Implement Local Socket Client
      • Local Socket Event
    • Test
  • Infra
    • CDK
      • SocketService
      • Service
      • Add Socket to other Services
  • Tests
API Gateway: ABC
Event Bus Arn: XYZ
Service Log Group: eventual-tests-execution-logs
Socket Endpoints: 
        socket1 - wss://someurl.com

Comment on lines 560 to 566
this.socketHandlersPrincipal =
this.socketHandlersList.length > 0 || this.local
? new DeepCompositePrincipal(
...(this.local ? [this.local.environmentRole] : []),
...this.socketHandlersList.map((f) => f.grantPrincipal)
)
: new UnknownPrincipal({ resource: this });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: generalize this redundant stuff in a function

Comment on lines 14 to 31
$connect: (
request: {
connectionId: string;
query?: Record<string, string | undefined>;
},
context: SocketHandlerContext
) => Promise<void> | void;
$disconnect: (
request: { connectionId: string },
context: SocketHandlerContext
) => Promise<void> | void;
$default: (
request: {
connectionId: string;
body?: string;
headers?: Record<string, string | undefined>;
},
context: SocketHandlerContext
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we drop the $ prefix?

Copy link
Contributor Author

@thantos thantos Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the benefit of keeping them is that we could support custom route names in the same object.

{
   $connect: () => {},
   $disconnect: () => {},
   $default: () => {},
   default: () => {} // custom route key named default
}

Copy link
Owner

@sam-goodwin sam-goodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What guarantees does the transactions have?

What happens if socket fails to send but dynamo write succeeds.

Copy link
Owner

@sam-goodwin sam-goodwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nervous about changing middleware? Do we have sufficient tests?

Comment on lines +152 to +162
defaultRouteOptions: {
// https://stackoverflow.com/a/72716478
// must create one integration per...
integration: new WebSocketLambdaIntegration("default", this.handler),
},
connectRouteOptions: {
integration: new WebSocketLambdaIntegration("Connect", this.handler),
authorizer: new WebSocketNoneAuthorizer(),
},
disconnectRouteOptions: {
integration: new WebSocketLambdaIntegration("Disconnect", this.handler),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dang, those LambdaIntegrations. I wonder if we can work around that?

Not high priority, but gah-damn that is bad

public execute(call: SocketCall): Promise<CallOutput<SocketCall>> {
return this.socketClient[call.operation.operation](
call.operation.socketName,
// @ts-ignore - typescript won't let me case the params...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean "case"?

Comment on lines +100 to +101
withMiddlewares<CommandContext, HttpResponse, HttpRequest>(
command.middlewares ?? [],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generalized the function to work for both socket and command.

SocketResponse,
SocketConnectionRequest
>(
socket.connectMiddlewares,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Middleware is only on connect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Web sockets are asymmetrical. You only get query strings during connect. Apig only allows authorizers for the connect route.

Though now that I think about it, it may be useful to pass all of the request types through with the route key to give the option to impact other routes. I was just thinking about auth.

Need to look at how apig handles the identity too.

@thantos
Copy link
Contributor Author

thantos commented Sep 14, 2023

What guarantees does the transactions have?

What happens if socket fails to send but dynamo write succeeds.

Same guarantee as the other side effects (emit event and send signal), which is there is none and currently no reporting of the errors.

I think once we move the calls to be downstream of the dynamo write, we can add a DLQ, reporting, and retry logic to the side effects.

@thantos thantos marked this pull request as ready for review September 14, 2023 21:38
@thantos thantos merged commit 2b91cda into main Sep 14, 2023
3 checks passed
@thantos thantos deleted the sussman/feat/socket branch September 14, 2023 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants